//
//  ZXXMainViewController.swift
//  Swift_Weibo
//
//  Created by 朱骁雄 on 16/4/8.
//  Copyright © 2016年 朱骁雄. All rights reserved.
//

import UIKit

class ZXXMainViewController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBer = ZXXMainTabBar()
        
        
        mainTabBer.composeClosure = {
            () -> () in
            print("加号点击")
        }
        
        self.setValue(mainTabBer, forKey: "tabBar")
        
        setupChildViewController()
    }
    
    private func setupChildViewController(){
        //        //创建控制器
        //        let homeVc = ZXXHomeTableViewController()
        //        homeVc.title = "首页"
        //        homeVc.tabBarItem.image = UIImage(named: "tabbar_home")
        //        addChildViewController(homeVc)
        setupChildViewController(ZXXHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        
        setupChildViewController(ZXXMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        
        setupChildViewController(ZXXDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        
        setupChildViewController(ZXXProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }
    
    private func setupChildViewController(controller: UIViewController,imageName:String,title:String){
        
        controller.title = title
        
        controller.tabBarItem.image = UIImage(named: imageName)
        
        //选中图片  拼接
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        
//        controller.view.backgroundColor = UIColor.orangeColor()
        
        
//        设置标题颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //包含导航控制器
        addChildViewController(UINavigationController(rootViewController: controller))
        
        
    }
    
    
    
}
